// animate(ele,attr,callback,speedTime)

function animate(ele,attrs,callback,speedTime){
    if(!!callback && !(callback instanceof Function)){
        speedTime = callback;
        callback = undefined;
    }

    if(speedTime){
        speedTime = speedTime;
    }else{
        speedTime = 20;
    }

    clearInterval(ele.timers);
    ele.timers = setInterval(function(){
        var flag = true;
        for (let key in attrs) {
            if(key === "zIndex"){
                ele.style[key] = attrs[key];
            }else{
                var current = 0;
                if(key === "opacity"){
                    current = getStyle(ele,key)*100;
                }else{
                    current = parseInt(getStyle(ele,key));
                }

                var speed = (attrs[key] - current)/10;
                speed = speed>0?Math.ceil(speed):Math.floor(speed);

                if(current != attrs[key]){
                    flag = false;
                    if(key === "opacity"){
                        ele.style[key] = (current + speed)/100;
                    }else{
                        ele.style[key] = current + speed + "px";
                    }
                }
            }
        }

        if(flag){
            clearInterval(ele.timers);
            if(!!callback){
                callback();
            }
        }
    }, speedTime);

}

//获取当前元素的css，返回值为css类型 加单位

function getStyle(obj,attr){
	return !!window.getComputedStyle ? window.getComputedStyle(obj,null)[attr] : obj.currentStyle[attr];
}